<template>
  <div>
    <!--    <div >-->
    <!--      <el-form :model="formData" :rules="rules" class="registerForm" ref="registerForm" label-width="80px">-->
    <!--        <el-form-item label="文件" prop="resourceFile">-->
    <!--          <el-button type="primary" plain size="small" @click="dialogFormVisible = true">上传作业</el-button><br>-->
    <!--          <el-dialog title="文件上传" :visible.sync="dialogFormVisible">-->
    <!--            <input id="fUpload" multiple type="file" />-->
    <!--            <div slot="footer" class="dialog-footer">-->
    <!--              <el-button @click="dialogFormVisible = false">取 消</el-button>-->
    <!--              <el-button type="primary" @click="commitFile()">确 定</el-button>-->
    <!--            </div>-->
    <!--          </el-dialog>-->
    <!--          <span v-show="fileShow" style="color: #a50912">请上传文件</span>-->
    <!--        </el-form-item>-->

    <!--        <el-form-item>-->
    <!--          <el-button type="primary"  class="submit_btn" @click="submitForm('registerForm')">提交</el-button>-->
    <!--        </el-form-item>-->
    <!--      </el-form>-->
    <!--    </div>-->



    <div>
      <el-table
          :data="scoreList"
          style="width: 100%">
        <el-table-column
            prop="commitName"
            label="作业名称"
            width="200">
        </el-table-column>
        <el-table-column
            prop="score"
            label="分数"
            width="200">
        </el-table-column>
        <el-table-column
            prop="comment"
            label="教师评语"
            width="200">
        </el-table-column>
        <el-table-column
            prop="correctDate"
            label="作业提交日期"
            width="200">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="200">
          <template slot-scope="scope">
            <el-button  v-on:click ="downloadByUrl(scope.row)" type="text" size="small">下载</el-button>
            <el-button  v-on:click ="deleteById(scope.row)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>


    </div>










  </div>
</template>
<script>
import axios from 'axios'
export default {
  components: {},
  // props:[],
  data() {
    return {
      activeNames: ['1'],
      scoreList:'',
      sno : sessionStorage.getItem("sno"),
      comId:this.$route.params.comId,
      hId: this.$route.params.hId,
      fileShow: false,
      // 文件上传
      fileList: [],
      resourceTypeOptions: [],
      formData: {
        resourceFile: null,
        resourceType: ''
      },
      //弹出框
      dialogTableVisible: false,
      dialogFormVisible: false,
      form: {
        name: '',
        region: '',
        date1: '',
        date2: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      },
      formLabelWidth: '120px',
      rules: {
        // 要以数组形式展示
        resourceFile: [
          { required: true, message: "请上传文件", trigger: "change" },
        ],
        // resourceType: [
        //   {
        //     required: true,
        //     message: "请选资料类型",
        //     trigger: "blur"
        //   }
        // ]
      }
    }
  },
  computed: {},
  watch: {},
  created() {
    var _this = this
    // axios.get('http://localhost:8080/jas/sport/student/getComidByStudent/'+this.sno).then(function (resp) {
    //   _this.comId = resp.data
    // })

    console.log("this+++++++++++++++++"+_this.comId)
    axios.get('http://localhost:8080/jas/sport/score/selectMyScore/'+this.hId+'/'+this.sno+'/'+this.comId).then(function (resp) {
      _this.scoreList = resp.data
    })

  },
  mounted() {
    // var that = this
    // console.log("this+++++++++++++++++"+that.comId)
    // axios.get('http://localhost:8080/jas/sport/student/selectMyScore/'+this.hId+'/'+this.sno+'/'+this.comId).then(function (resp) {
    //   that.scoreList = resp.data
    // })


    // axios.get('http://localhost:8080/jas/sport/student/getComidByStudent/'+this.sno).then(function (resp) {
    //   _this.comId = resp.data
    // })
  },
  methods: {
    handleChange(val) {
      console.log(val);
    },

    downloadByUrl(row) {
      console.log(row)
      const a = document.createElement('a'); // 创建a标签
      let url = row.commitedJobUrl
      var x = url.indexOf('/');
      for (var i = 0; i < 2; i++) {
        x = url.indexOf('/', x + 1);
      }
      var endUrl = url.slice(x)
      console.log(endUrl)
      a.setAttribute('download', row.commitName);// download属性
      a.setAttribute('href', endUrl);// href链接
      a.click();// 自执行点击事件
    },
    deleteById(row){
      axios.get('http://localhost:8080/jas/sport/score/deleteById/'+row.id).then(function (resp) {

        // this.$router.push({name:'ViewNoticeDetail',params:{noticeId:row.id}})
      })
      // location.reload();
      this.$router.push('/StudentMainPage/CourseType')
    },
    del(id){
      axios.get('http://localhost:8080/jas/sport/score/deleteById/'+id).then(function (resp) {

        // this.$router.push({name:'ViewNoticeDetail',params:{noticeId:row.id}})
      })
      location.reload();
    },

    // 文件上传
    commitFile(){
      this.dialogFormVisible = false
      var fp = $("#fUpload");
      var items = fp[0].files;
      if ((items[0]) == undefined || (items[0]) == null || (items[0]) == ''){
        this.fileShow = true
        return
      }else {
        this.fileShow = false
        this.formData.resourceFile = items[0]
      }
    },
    //文件上传
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      this.formData.resourceFile = file.raw
      this.$message('ok');
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    //其他
    submitForm(formName){
      if (this.formData.resourceFile == ''|| this.formData.resourceFile ==null){
        this.fileShow = true
        return
      }
      this.$refs[formName].validate(valid => {
        if (valid) {
          var _this = this
          var f = new FormData();
          f.append("resourceFile",this.formData.resourceFile)
          f.append("hId",this.hId)
          f.append("sNo",this.sno)
          f.append("comId",this.comId)
          axios.post('http://localhost:8080/jas/sport/score/saveHomework',f).then(function (resp) {
            alert(resp.data)
            _this.$router.push('/StudentMainPage/CourseHomework')
          })
        } else {
          console.log("error submit!!");
          return false;
        }
      });


    }
  }
}

</script>
<style>
.el-upload__tip {
  line-height: 1.2;
}

</style>
